package com.jy.adscm.hospital.support;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.hospital.bean.JyHospitalEquipment;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;

public class HospitalSupport<T> {

    private T data;

    public HospitalSupport(){}

    public HospitalSupport(T data){
        this.data = data;
    }

    /**
     * 构造wrapper
     * @param baseId
     * @param type
     * @param token
     * @return
     */
    public Wrapper<T> loadWrapper(Long baseId, int type,Long formId, Token token)throws AdscmSystemException{
        Wrapper<T> wrapper = null;
        if (token != null){
            JyUser user = token.getUser();
            if (user != null){
                wrapper = new EntityWrapper<>();
                if (type == 1){
                    wrapper.eq("input_unit",0);
                }else if(type == 2){
                    Integer unitId = user.getUnitId();
                    if (unitId == 0){
                        //当前登录的是厂商人员，就查询其他所有经销商的
                        wrapper.where("input_unit != 0");
                    }else {
                        wrapper.where("input_unit != 0 and input_unit !="+unitId);
                    }
                }else if(type == 3) {
                    //如果查询经销商自己的，就必须传入formId
                    if ( formId != null && formId > 0){

                    }else {
                        throw new AdscmSystemException("查询经销商的过程记录，必须传入报单ID");
                    }
                    wrapper.eq("input_unit",user.getUnitId());
                    wrapper.eq("form_id",formId);
                }else {
                    //type == 4 ，就是厂商的审核员查询那条记录，只查看报单的那条数据对应的过程记录
                    wrapper.eq("form_id",formId);
                }
                wrapper.eq("base_id",baseId);
            }
        }
        return wrapper;
    }
}
